import numpy as np
import pandas as pd
import sqlite3
import redis
import json
# Create your views here.

if __name__ == '__main__':

    db_path = '../db.sqlite3'

else:

    db_path = 'db.sqlite3'


conn = sqlite3.connect(db_path, check_same_thread = False)

r = redis.Redis(host='192.168.92.132', port=6379, password = '1', db = '0')


class DouBanAna:

    def __init__(self):

        #conn = sqlite3.connect(db_path)

        self.df = pd.read_sql('SELECT * FROM DMSC_csv', conn)

    def how_many_reviews_are_there_per_movie(self):

        info = self.df.groupby('Movie_Name_CN').count()['index']

        info_dict = info.to_dict()

        info_dict_js = json.dumps(info_dict)

        r.set('how_many_reviews_are_there_per_movie',info_dict_js)

        return info

    def total_thumb_up_per_film(self):

        info = self.df.groupby('Movie_Name_CN').sum()['Like']

        return info




if __name__ == '__main__':

    x = DouBanAna()
    y = x.how_many_reviews_are_there_per_movie()

        

        

    
